package com.example.manzararecyclerview
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.tek_satir_view.*
class MainActivity : AppCompatActivity() {
var tumManzalar = ArrayList<Manzara>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
veriKaynagınıHazırla()
var myAdapter = ManzaraAdabter(tumManzalar)
recyclerViewManzara.adapter = myAdapter
var linearViewHorizontal = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recyclerViewManzara.layoutManager = linearViewHorizontal
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
var id: Int = item.itemId
when (id) {
R.id.linearViewHorizontal -> {
var linearViewHorizontal =
LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
recyclerViewManzara.layoutManager = linearViewHorizontal
}
R.id.linearViewVertical -> {
var linearViewVertical =
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recyclerViewManzara.layoutManager = linearViewVertical
}
R.id.menuGrid -> {
var menuGrid = GridLayoutManager(this, 2)
recyclerViewManzara.layoutManager = menuGrid
}
R.id.menuStagerdHorizantel -> {
var menuStagerdHorizantel =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.HORIZONTAL)
recyclerViewManzara.layoutManager = menuStagerdHorizantel
}
R.id.menuStagerdVertical -> {
var menuStagerdVertical =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
recyclerViewManzara.layoutManager = menuStagerdVertical
}
}
return super.onOptionsItemSelected(item)
}
fun veriKaynagınıHazırla(): ArrayList<Manzara>{
var tumResimler = arrayOf(
R.drawable.thumb1,
R.drawable.thumb2,
R.drawable.thumb3,
R.drawable.thumb4,
R.drawable.thumb5,
R.drawable.thumb6,
R.drawable.thumb7,
R.drawable.thumb8,
R.drawable.thumb9,
R.drawable.thumb10,
R.drawable.thumb11,
R.drawable.thumb12,
R.drawable.thumb14,
R.drawable.thumb15,
R.drawable.thumb16,
R.drawable.thumb17,
R.drawable.thumb18,
R.drawable.thumb19,
R.drawable.thumb20,
R.drawable.thumb21,
R.drawable.thumb22,
R.drawable.thumb23,
R.drawable.thumb24,
R.drawable.thumb25,
R.drawable.thumb26,
R.drawable.thumb27,
R.drawable.thumb28,
R.drawable.thumb29,
R.drawable.thumb30,
R.drawable.thumb31,
R.drawable.thumb32,
R.drawable.thumb33,
R.drawable.thumb34,
R.drawable.thumb35,
R.drawable.thumb36,
R.drawable.thumb37,
R.drawable.thumb38,
R.drawable.thumb39,
R.drawable.thumb40
)
for (i in 0..tumResimler.size - 1) {
var eklenecekManzara = Manzara("Manzara" + i, "Açıklama" + i, tumResimler[i])
tumManzalar.add(eklenecekManzara)
}
return tumManzalar
}
}